package com.vae.media.api;

import com.vae.base.model.video.RestResponse;
import com.vae.domain.entity.MediaFiles;
import com.vae.media.service.MediaFilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.commons.lang3.StringUtils;
/**
 * @author: 35238
 * 功能: 视频预览的视频
 * 时间: 2024-05-23 21:29
 */
@Api(value = "媒资文件管理",tags = "媒资文件管理接口")
@RestController
@RequestMapping("/open")
public class MediaOpenController {

    @Autowired
    MediaFilesService mediaFilesService;

    /**
     * 预览文件
     * @param mediaId
     * @return
     */
    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable String mediaId){

        MediaFiles mediaFiles = mediaFilesService.getFileById(mediaId);
        if(mediaFiles == null || StringUtils.isEmpty(mediaFiles.getUrl())){
            return RestResponse.validfail("该视频上传有误，请重新上传");
        }
        return RestResponse.success(mediaFiles.getUrl());

    }
}